/**
  校际交流项目 - 申请
*/
<template>
    <div class="topic-info" style="width:100%;">
        <div class="project-application-container" style="height: 30px;">
            <el-breadcrumb style="float: left;" separator="/">
                <el-breadcrumb-item :to="{ path: '/InterSchoolComAppList' }">
                    <span @click="returnList">校际交流院级项目申请</span>
                </el-breadcrumb-item>
                <el-breadcrumb-item>
                    <span v-if="submitType === 'add'">申请</span>
                    <span v-else-if="submitType === 'edit'">编辑</span>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <el-card>
            <el-button style="float:right" @click="returnList">返回</el-button>
            <span class="top-title">
                <h3 v-if="submitType === 'add'">校际交流院级项目申请-申请</h3>
                <h3 v-else-if="submitType === 'edit'">校际交流院级项目申请-编辑</h3>
            </span>
            <hr />
            <el-form
                :model="proForm"
                ref="proForm"
                :rules="baseInfoRules"
                label-position="top"
                label-suffix="："
                :tooltipEffect="tooltipEffect"
            >
                <span class="topic-form-title">
                    <h3>个人信息</h3>
                </span>
                <el-row :gutter="24">
                    <el-col :span="6">
                        <el-form-item label="学院" prop="teacherFacultyName">
                            <el-input
                                v-model="proForm.teacherFacultyName"
                                class="topic-input-select"
                                maxlength="32"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="工号" prop="teacherId">
                            <el-input
                                v-model="proForm.teacherId"
                                class="topic-input-select"
                                maxlength="32"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="姓名" prop="teacherName">
                            <el-input
                                v-model="proForm.teacherName"
                                class="topic-input-select"
                                maxlength="32"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="职称" prop="teacherTitleName">
                            <el-input
                                v-model="proForm.teacherTitleName"
                                class="topic-input-select"
                                maxlength="32"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="6">
                        <el-form-item label="手机号码" prop="teacherPhone">
                            <el-input
                                v-model="proForm.teacherPhone"
                                class="topic-input-select"
                                maxlength="32"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="电子邮件地址" prop="teacherEmail">
                            <el-tooltip class="item" effect="light" :content="proForm.teacherEmail" placement="top" :disabled="showTip">
                            <el-input
                                v-model="proForm.teacherEmail"
                                class="topic-input-select"
                                maxlength="320"
                            ></el-input>
                            </el-tooltip>
                        </el-form-item>
                    </el-col>
                </el-row>

                <span class="topic-form-title">
                    <h3>申请项目情况</h3>
                </span>
                <el-row :gutter="24">
                    <el-col :span="6">
                        <el-form-item label="培养层次" prop="trainingCode">
                            <el-select
                                v-model="proForm.trainingCode"
                                class="topic-input-select"
                                multiple
                                placeholder
                            >
                                <el-option
                                    v-for="item in source.teachLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="18">
                        <el-form-item label="项目名称" prop="projectName">
                            <el-input
                                v-model="proForm.projectName"
                                class="topic-input-select"
                                maxlength="32"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="12">
                        <el-form-item label="合作大学（模糊查询）" prop="projectCollegeId">
                            <el-select
                                v-model="proForm.projectCollegeId"
                                class="topic-input-select"
                                filterable
                                @change="getCollege"
                                placeholder
                            >
                                <el-option
                                    v-for="item in source.collegeCn"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="合作大学英文名称（模糊查询）" prop="projectCollegeEn">
                            <el-select
                                v-model="proForm.projectCollegeEn"
                                class="topic-input-select"
                                filterable
                                @change="getCollege"
                                placeholder
                            >
                                <el-option
                                    v-for="item in source.collegeEn"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="6">
                        <el-form-item label="国家/地区" prop="projectNationName">
                            <el-input
                                v-model="proForm.projectNationName"
                                class="topic-input-select"
                                maxlength="32"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="留学内容" prop="projectStudyAbroadId">
                            <el-select
                                v-model="proForm.projectStudyAbroadId"
                                class="topic-input-select"
                                filterable
                                placeholder
                            >
                                <el-option
                                    v-for="item in source.contentList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="项目开始时间" prop="projectStartTimeStr">
                            <el-date-picker
                                v-model="proForm.projectStartTimeStr"
                                type="date"
                                class="topic-input-select"
                                value-format="yyyy-MM-dd"
                                :picker-options="startDatePicker"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="项目结束时间" prop="projectEndTimeStr">
                            <el-date-picker
                                v-model="proForm.projectEndTimeStr"
                                type="date"
                                class="topic-input-select"
                                value-format="yyyy-MM-dd"
                                :picker-options="endDatePicker"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="6">
                        <el-form-item label="每年中方留学生名额" prop="projectInlandNumber">
                            <el-input
                                v-model="proForm.projectInlandNumber"
                                class="topic-input-select"
                                maxlength="32"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="每年外方留学生名额" prop="projectOutlandNumber">
                            <el-input
                                v-model="proForm.projectOutlandNumber"
                                class="topic-input-select"
                                maxlength="32"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="项目负责人" prop="projectHeadId">
                            <!-- <el-select
                                v-model="proForm.projectHeadId"
                                class="topic-input-select"
                                filterable
                                clearable
                                v-el-select-loadmore="loadmore"
                                :filter-method="dataFilter"
                                @visible-change="clearHeadId"
                                placeholder
                            >
                                <el-option
                                    v-for="item in source.teacherList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>-->
                            <select-For-Page
                                :queryType="1"
                                :val="proForm.projectHeadId"
                                :queryFaculty="queryFaculty"
                                @returnVal="getProjectHeadId"
                            ></select-For-Page>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="项目联系人" prop="projectContactId">
                            <!-- <el-select
                                v-model="proForm.projectContactId"
                                class="topic-input-select"
                                filterable
                                clearable
                                v-el-select-loadmore="loadmore"
                                :filter-method="dataFilter"
                                @visible-change="clearContactId"
                                placeholder
                            >
                                <el-option
                                    v-for="item in source.teacherList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>-->
                            <select-For-Page
                                :queryType="1"
                                :val="proForm.projectContactId"
                                :queryFaculty="queryFaculty"
                                @returnVal="changekey"
                            ></select-For-Page>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="12">
                        <el-form-item label="所涉及学院（可多选）" prop="facultyCode">
                            <el-select
                                v-model="proForm.facultyCode"
                                class="topic-input-select"
                                filterable
                                multiple
                                placeholder
                            >
                                <el-option
                                    v-for="item in source.facultyList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="24">
                        <el-form-item label="备注" prop="projectRemark">
                            <el-input
                                v-model="proForm.projectRemark"
                                class="topic-input-select"
                                type="textarea"
                                :rows="6"
                                maxlength="500"
                                show-word-limit
                                placeholder
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <br />
                <span class="topic-form-title">
                    <h3 style="float: left">附件管理</h3>
                </span>
                <span>（按要求上传协议扫描件）您可以上传图片(jpg、png、jpeg、bmp)，PDF，大小不要超过 5MB；</span>
                <div style="float: right">
                    <el-upload
                        v-model="proForm.insurancePremium"
                        class="upload-demo"
                        action="/api/commonservice/obsfile/uploadfile"
                        :before-upload="beforeUpload"
                        :show-file-list="false"
                        :data="uploadConfig.data"
                        :on-exceed="handleExceed"
                        :on-success="handlerUploadSuccess"
                        :on-error="handlerUploadError"
                        multiple
                        :file-list="uploadFileList"
                        :limit="10"
                    >
                        <el-button size="small" type="primary">上传附件</el-button>
                    </el-upload>
                </div>
                <edu-table
                    :data="uploadFileList"
                    :tooltipEffect="tooltipEffect"
                    stripe
                    :selection="false"
                    :order="true"
                    :pagination="false"
                >
                    <edu-table-column prop label="已上传文件">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="downFile(scope.row)"
                            >{{scope.row.fileName}}</el-button>
                        </template>
                    </edu-table-column>
                    <edu-table-column prop="fileExt" label="文件类型"></edu-table-column>
                    <edu-table-column prop="fileTime" label="上传时间"></edu-table-column>
                    <edu-table-column prop="fileSize" label="文件大小"></edu-table-column>
                    <edu-table-column prop label="操作">
                        <template slot-scope="scope">
                            <el-button type="text" @click="delFile(scope.row)">删除</el-button>
                        </template>
                    </edu-table-column>
                </edu-table>
            </el-form>
            <div>
                <hr />
                <div class="edu-opertion-bar">
                    <div class="float-right" v-show="!ifShowDetail">
                        <el-button @click="onCancel">取消</el-button>
                        <el-button type="primary" @click="onSubmit(0)">保存</el-button>
                        <el-button
                            type="primary"
                            @click="onSubmit(1)"
                            v-show="pageFrom === 'app'"
                        >提交</el-button>
                    </div>
                </div>
            </div>
        </el-card>
    </div>
</template>
<script>
import filters from 'common/src/filters'
import InterSchoolComAppApi from 'common/src/api/interSchoolExchange/InterSchoolComApp'
import { downloadfile } from 'common/src/api/upload'
import { queryDic } from 'common/src/api/dictionary'
import selectForPage from './common/selectForPage'
import UTILS from 'common/src/utils/utils'
import * as INDEX from 'common/src/utils/index'
import { Loading } from 'element-ui'

export default {
    components: {
        'select-For-Page': selectForPage
    },
    // directives: {
    //     'el-select-loadmore': {
    //         bind(el, binding) {
    //             // 获取element-ui定义好的scroll盒子
    //             const SELECTWRAP_DOM = el.querySelector(
    //                 '.el-select-dropdown .el-select-dropdown__wrap'
    //             )
    //             SELECTWRAP_DOM.addEventListener('scroll', function() {
    //                 /**
    //                  * scrollHeight 获取元素内容高度(只读)
    //                  * scrollTop 获取或者设置元素的偏移值,常用于, 计算滚动条的位置, 当一个元素的容器没有产生垂直方向的滚动条, 那它的scrollTop的值默认为0.
    //                  * clientHeight 读取元素的可见高度(只读)
    //                  * 如果元素滚动到底, 下面等式返回true, 没有则返回false:
    //                  * ele.scrollHeight - ele.scrollTop === ele.clientHeight;
    //                  */
    //                 const condition = this.scrollHeight - this.scrollTop <= this.clientHeight
    //                 if (condition) {
    //                     binding.value()
    //                 }
    //             })
    //         }
    //     }
    // },
    name: '',
    props: {
        submitType: {
            type: String,
            default: ''
        },
        pageFrom: {
            type: String,
            default: ''
        },
        projectId: {
            type: Number,
            default: ''
        }
    },
    data() {
        return {
            startDatePicker: this.beginDate(),
            endDatePicker: this.processDate(),
            uploadFileList: [],
            num: 0,
            showTip: true,
            queryFaculty: '',
            flag: false,
            source: {
                facultyList: [],
                teachLevel: [],
                teacherList: [],
                collegeCn: [],
                collegeEn: [],
                contentList: []
            },
            formData: {
                pageNum_: 1,
                pageSize_: 10,
                condition: {
                    teacherLable: ''
                }
            },
            proForm: {
                teacherId: '',
                teacherName: '',
                teacherFacultyName: '',
                teacherTitleName: '',
                teacherPhone: '',
                teacherEmail: '',
                projectName: '',
                trainingCode: [],
                facultyCode: [],
                projectCollegeId: null,
                projectCollegeEn: null,
                projectStudyAbroadId: null,
                projectStartTimeStr: '',
                projectEndTimeStr: '',
                projectInlandNumber: '',
                projectOutlandNumber: '',
                projectHeadId: null,
                projectContactId: null,
                projectRemark: '',
                trainings: [],
                faculties: [],
                files: [],
                projectNationName: ''
            },
            baseInfoRules: {
                teacherPhone: [
                    { required: true, message: '请输入', trigger: 'blur' },
                    { validator: this.checkPhone, trigger: 'blur' }
                ], //电话号码
                teacherEmail: [
                    { required: true, message: '请输入', trigger: 'blur' },
                    { validator: this.checkEmail, trigger: 'blur' }
                ], // 邮箱
                trainingCode: [{ required: true, message: '请选择', trigger: 'change' }], // 培养层次
                projectName: [{ required: true, message: '请输入', trigger: 'blur' }], // 项目名称
                projectCollegeId: [{ required: true, message: '请选择', trigger: 'change' }], // 合作大学
                projectCollegeEn: [{ required: true, message: '请选择', trigger: 'change' }], // 合作大学英文名称
                projectNationName: [{ required: true, message: '请选择', trigger: 'change' }], // 国家/地区
                projectStudyAbroadId: [{ required: true, message: '请选择', trigger: 'change' }], // 留学内容
                projectStartTimeStr: [{ required: true, message: '请选择', trigger: 'change' }], // 开始时间
                projectEndTimeStr: [{ required: true, message: '请选择', trigger: 'change' }], // 结束时间
                projectInlandNumber: [{ required: true, message: '请输入', trigger: 'blur' }], // 每年中方留学生名额
                projectOutlandNumber: [{ required: true, message: '请输入', trigger: 'blur' }], // 每年外方留学生名额
                facultyCode: [{ required: true, message: '请选择', trigger: 'change' }], // 学院
                projectHeadId: [{ required: true, message: '请选择', trigger: 'change' }], // 项目负责人工号
                projectContactId: [{ required: true, message: '请选择', trigger: 'change' }] // 项目联系人工号
            },

            uploadConfig: {
                data: { bucketname: 'face', folderpath: 'file' }
            }
        }
    },
    watch: {
        'proForm.teacherEmail': {
            handler(newVal) {
                if (newVal &&  newVal.length > 20) {
                    this.showTip = false
                } else {
                    this.showTip = true
                }
            },
            deep: true,
            immediate: true
        }
    },
    filters: {
        time(val) {
            return INDEX.parseTime(val, '{y}-{m}-{d}')
        }
    },
    created() {
        this.getTeacherInfo()

        if (this.submitType === 'add') {
            // this.getList(this.formData)
            this.getCollege()
        }

        this.getTeacherLevel()
        this.initOptions()
        this.getContent()
        if (this.submitType === 'edit') {
            this.getData()
        }
        // 获取登陆用户学院
        if (JSON.parse(localStorage.getItem('sessiondata')).mockUser) {
            this.queryFaculty = JSON.parse(localStorage.getItem('sessiondata')).mockUser.faculty
        } else if (JSON.parse(localStorage.getItem('sessiondata')).user) {
            this.queryFaculty = JSON.parse(localStorage.getItem('sessiondata')).user.faculty
        }
    },
    mounted() {
        this.num = 0
        this.$refs['proForm'].clearValidate()
    },
    methods: {
        changekey(val) {
            this.proForm.projectContactId = val
        },
        // 打开下拉框时候重置下拉框内容
        clearHeadId(val) {
            if (val && !this.proForm.projectHeadId) {
                this.formData.pageNum_ = 1
                this.formData.condition.teacherLable = ''
                this.source.teacherList = []
                this.getList(this.formData)
            } else if (val && this.proForm.projectHeadId) {
                this.formData.pageNum_ = 1
                this.formData.condition.teacherLable = this.proForm.projectHeadId
                this.source.teacherList = []
                this.getList(this.formData)
            }
        },
        getProjectHeadId(val) {
            this.proForm.projectHeadId = val
        },
        // 打开下拉框时候重置下拉框内容
        // clearHeadId(val) {
        //     if (val && !this.proForm.projectHeadId) {
        //         this.formData.pageNum_ = 1
        //         this.formData.condition.teacherLable = ''
        //         this.source.teacherList = []
        //         this.getList(this.formData)
        //     } else if (val && this.proForm.projectHeadId) {
        //         this.formData.pageNum_ = 1
        //         this.formData.condition.teacherLable = this.proForm.projectHeadId
        //         this.source.teacherList = []
        //         this.getList(this.formData)
        //     }
        // },
        // // 打开下拉框时候重置下拉框内容
        // clearContactId(val) {
        //     if (val && !this.proForm.projectContactId) {
        //         this.formData.pageNum_ = 1
        //         this.formData.condition.teacherLable = ''
        //         this.source.teacherList = []
        //         this.getList(this.formData)
        //     } else if (val && this.proForm.projectContactId) {
        //         this.formData.pageNum_ = 1
        //         this.formData.condition.teacherLable = this.proForm.projectContactId
        //         this.source.teacherList = []
        //         this.getList(this.formData)
        //     }
        // },
        // 返回列表页
        returnList() {
            this.$confirm('取消将不会保存当前设置，是否确定?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$emit('returnVal', 'list')
            })
        },

        // 根据项目类型查找留学内容
        getContent() {
            this.source.contentList = []
            let parm = {
                id: 3
            }
            InterSchoolComAppApi.selectContent(parm).then(res => {
                if (res.data) {
                    res.data.forEach(con => {
                        this.source.contentList.push({
                            label: con.content,
                            value: con.id
                        })
                    })
                }
            })
        },
        getTeacherInfo() {
            InterSchoolComAppApi.teacherDetail({}).then(res => {
                this.proForm.teacherFacultyName = res.data.teacherFacultyName
                this.proForm.teacherId = res.data.teacherId
                this.proForm.teacherName = res.data.teacherName
                this.proForm.teacherTitleName = res.data.teacherTitleName
                this.proForm.teacherPhone = res.data.teacherPhone
                this.proForm.teacherEmail = res.data.teacherEmail
            })
        },

        // 获取详情
        getData() {
            let _this = this
            let parm = {
                projectId: this.projectId
            }
            // 获取合作大学下拉列表
            InterSchoolComAppApi.getCollegeListByNationCode({}).then(resT => {
                resT.data.forEach(col => {
                    this.source.collegeCn.push({
                        value: col.id,
                        label: col.collegeName
                    })
                    this.source.collegeEn.push({
                        value: col.id,
                        label: col.collegeNameEn
                    })
                })

                // 获取编辑页详情
                InterSchoolComAppApi.get(parm).then(res => {
                    if (res.code === 200) {
                        // if (res.data.projectHeadId) {
                        //     let parmHeadId = {
                        //         pageNum_: 1,
                        //         pageSize_: 10,
                        //         condition: {
                        //             teacherLable: res.data.projectHeadId
                        //         }
                        //     }
                        //     this.getList(parmHeadId)
                        // }
                        // if (res.data.projectContactId) {
                        //     let parmContactId = {
                        //         pageNum_: 1,
                        //         pageSize_: 10,
                        //         condition: {
                        //             teacherLable: res.data.projectContactId
                        //         }
                        //     }
                        //     this.getList(parmContactId)
                        // }
                        for (let key in _this.proForm) {
                            _this.proForm[key] = res.data[key]
                        }

                        // 如果合作大学被删除  置空编辑页的合作大学名称、合作大学英文名称、国际/地区
                        let ifexist = true
                        this.source.collegeCn.forEach(col => {
                            if (col.value === res.data.projectCollegeId) {
                                ifexist = false
                            }
                        })
                        if (ifexist) {
                            this.proForm.projectCollegeId = null
                            this.proForm.projectCollegeEn = null
                            this.proForm.projectNationName = ''
                        }

                        this.proForm.facultyCode = []
                        this.proForm.trainingCode = []
                        this.proForm.projectEndTimeStr = res.data.projectEndTime
                        this.proForm.projectStartTimeStr = res.data.projectStartTime
                        res.data.faculties.forEach(fac => {
                            _this.proForm.facultyCode.push(fac.facultyCode)
                        })
                        res.data.trainings.forEach(tra => {
                            _this.proForm.trainingCode.push(tra.trainingCode)
                        })

                        this.uploadFileList = res.data.files
                        this.approveHistory = res.data.processes
                    }
                })
            })
        },

        // // 校验项目名称是否重复
        // checkExist() {
        //     let parm = {
        //         projectId: this.projectId,
        //         projectName: this.proForm.projectName
        //     }
        //     InterSchoolComAppApi.exist(parm).then(res => {
        //         if (res.data.exist === true) {
        //             this.flag = false
        //             return
        //         } else if (res.data.exist === false) {
        //             this.flag = true
        //         }
        //     })
        // },

        // loadmore() {
        //     this.formData.pageNum_++
        //     this.getList(this.formData)
        // },

        // dataFilter(val) {
        //     let _this = this
        //     this.source.teacherList = []
        //     this.formData.pageNum_ = 1
        //     this.formData.condition.teacherLable = val
        //     // 每次进来的时候都将之前的清除掉，
        //     // 如果还没到500ms的时候就将之前的清除掉，
        //     // 这样就不会触发之前setTimeout绑定的事件，
        //     //  如果超过500ms，之前的事件就会被触发下次进来的时候同样清除之前的timer
        //     clearTimeout(_this.timer)
        //     _this.timer = setTimeout(function() {
        //         // 切换为搜索
        //         _this.getList(_this.formData)
        //     }, 500)
        // },

        // // 获取项目负责人
        // getList(formData) {
        //     InterSchoolComAppApi.queryTeachers(formData).then(res => {
        //         if (res.data) {
        //             res.data.list.forEach(teacher => {
        //                 this.source.teacherList.push({
        //                     label: teacher.teacherLable,
        //                     value: teacher.teacherId
        //                 })
        //             })
        //         }
        //     })
        // },

        // 合作大学（模糊查询）
        getCollege(id) {
            let parm = {
                collegeId: id
            }
            if (id) {
                this.proForm.projectCollegeEn = id
                this.proForm.projectCollegeId = id
                InterSchoolComAppApi.getCollegeListByNationCode(parm).then(res => {
                    this.proForm.projectNationName = res.data[0].nationName
                })
            } else {
                InterSchoolComAppApi.getCollegeListByNationCode(parm).then(res => {
                    res.data.forEach(col => {
                        this.source.collegeCn.push({
                            value: col.id,
                            label: col.collegeName
                        })
                        this.source.collegeEn.push({
                            value: col.id,
                            label: col.collegeNameEn
                        })
                    })
                })
            }
        },

        beginDate() {
            let _this = this
            return {
                disabledDate(time) {
                    if (_this.proForm.projectEndTimeStr) {
                        //如果结束时间不为空，则小于结束时间
                        return new Date(_this.proForm.projectEndTimeStr).getTime() < time.getTime()
                    } else {
                        // return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
                    }
                }
            }
        },
        processDate() {
            let _this = this
            return {
                disabledDate(time) {
                    if (_this.proForm.projectStartTimeStr) {
                        //如果开始时间不为空，则结束时间大于开始时间
                        return (
                            new Date(_this.proForm.projectStartTimeStr).getTime() >
                            time.getTime() + 24 * 60 * 60 * 1000
                        )
                    } else {
                        // return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
                    }
                }
            }
        },
        // 校验手机号码
        checkPhone(rule, value, callback) {
            let regExp = /^1[23456789]\d{9}$/
            if (!regExp.test(value)) {
                callback(new Error(this.$t('projectApplication.validateStudentPhone')))
            } else {
                callback()
            }
        },
        // 校验电子邮件地址
        checkEmail(rule, value, callback) {
            let regExp = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
            if (!regExp.test(value)) {
                callback(new Error(this.$t('projectApplication.validateStudentEmail')))
            } else {
                callback()
            }
        },
        // 获取培养层次
        getTeacherLevel() {
            InterSchoolComAppApi.queryTrainings().then(res => {
                res.data.forEach(level => {
                    this.source.teachLevel.push({
                        label: level.trainingName,
                        value: level.trainingCode
                    })
                })
            })
        },

        async initOptions() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: [
                    'X_YX' // 学院
                ]
            }
            await queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        facultyList: 'X_YX' // 学院
                    },
                    res.data,
                    this.source
                )
            })
        },
        // 取消
        onCancel() {
            this.$confirm('取消将不会保存当前设置，是否确定?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$emit('returnVal', 'list')
            })
        },
        // 保存/提交
        onSubmit(type) {
            let _this = this
            this.proForm.trainings = []
            this.proForm.faculties = []
            if (this.proForm.trainingCode) {
                this.proForm.trainingCode.forEach(tra => {
                    this.proForm.trainings.push({
                        trainingCode: tra
                    })
                })
            }
            if (this.proForm.facultyCode) {
                this.proForm.facultyCode.forEach(faculty => {
                    this.proForm.faculties.push({
                        facultyCode: faculty
                    })
                })
            }
            if (this.proForm.projectStudyAbroadId) {
                this.source.contentList.forEach(con => {
                    if (this.proForm.projectStudyAbroadId === con.value) {
                        this.proForm.projectStudyAbroadContent = con.label
                    }
                })
            }
            this.proForm.files = this.uploadFileList
            this.$refs.proForm.validate(valid => {
                if (valid) {
                    if (_this.uploadFileList.length === 0) {
                        _this.$message.error('请至少上传一个附件')
                        return
                    } else {
                        let parm = {
                            projectId: _this.projectId,
                            projectName: _this.proForm.projectName
                        }

                        // 校验项目名称是否存在
                        InterSchoolComAppApi.exist(parm).then(res => {
                            if (res.data.exist === true) {
                                _this.$message.error('项目名称已经存在')
                                return
                            } else if (res.data.exist === false) {
                                // 新增页
                                if (_this.submitType === 'add') {
                                    // 保存
                                    if (type === 0) {
                                        // 教师申请
                                        if (_this.pageFrom === 'app') {
                                            InterSchoolComAppApi.add(_this.proForm).then(res => {
                                                if (res.code === 200) {
                                                    _this.$message({
                                                        message: '保存成功',
                                                        type: 'success'
                                                    })
                                                    _this.$emit('returnVal', 'list')
                                                }
                                            })
                                            // 校级新增
                                        } else if (_this.pageFrom === 'admin') {
                                            InterSchoolComAppApi.addProject(_this.proForm).then(
                                                res => {
                                                    if (res.code === 200) {
                                                        _this.$message({
                                                            message: '保存成功',
                                                            type: 'success'
                                                        })
                                                        _this.$emit('returnVal', 'list')
                                                    }
                                                }
                                            )
                                        }
                                        // 提交
                                    } else if (type === 1) {
                                        InterSchoolComAppApi.add(_this.proForm).then(res => {
                                            if (res.code === 200) {
                                                let parm = {
                                                    projectId: res.data.projectId
                                                }
                                                InterSchoolComAppApi.submit(parm).then(resT => {
                                                    if (resT.code === 200) {
                                                        _this.$message({
                                                            message: '提交成功',
                                                            type: 'success'
                                                        })
                                                        _this.$emit('returnVal', 'list')
                                                    }
                                                })
                                            }
                                        })
                                    }
                                } else if (_this.submitType === 'edit') {
                                    _this.proForm.projectId = _this.projectId
                                    if (type === 0) {
                                        // 教师申请
                                        if (_this.pageFrom === 'app') {
                                            InterSchoolComAppApi.modify(_this.proForm).then(res => {
                                                if (res.code === 200) {
                                                    _this.$message({
                                                        message: '保存成功',
                                                        type: 'success'
                                                    })
                                                    _this.$emit('returnVal', 'list')
                                                }
                                            })
                                            // 校级新增
                                        }
                                        // 提交
                                    } else if (type === 1) {
                                        InterSchoolComAppApi.modify(_this.proForm).then(res => {
                                            if (res.code === 200) {
                                                let parm = {
                                                    projectId: res.data.projectId
                                                }
                                                InterSchoolComAppApi.submit(parm).then(resT => {
                                                    if (resT.code === 200) {
                                                        _this.$message({
                                                            message: '提交成功',
                                                            type: 'success'
                                                        })
                                                        _this.$emit('returnVal', 'list')
                                                    }
                                                })
                                            }
                                        })
                                    }
                                }
                            }
                        })
                    }
                }
            })
        },
        delFile(row) {
            this.uploadFileList.forEach((val, index) => {
                if (row.fileId === val.fileId) {
                    this.uploadFileList.splice(index, 1)
                }
            })
        },
        downFile(row) {
            downloadfile(row.fileId)
        },

        handleExceed(files, fileList) {
            this.$message.error(`当前限制上传10个文件`)
        },
        beforeUpload(file) {
            const fileSizeFlag = file.size && file.size / 1024 / 1024 < 5
            let fileType = file.name.substring(file.name.lastIndexOf('.') + 1)
            let uploadFlag = ''
            let fileNameLen = file.name.length < 65
            uploadFlag =
                fileType === 'jpg' ||
                fileType === 'jpeg' ||
                fileType === 'png' ||
                fileType === 'bmp' ||
                fileType === 'pdf'

            let compFileName = true
            this.uploadFileList.forEach(val => {
                if (val.fileName === file.name) {
                    compFileName = false
                }
            })
            if (!compFileName) {
                window.vueApp.showMsgBox({
                    message: '已上传相同名称的文件，请修改文件名称后重新上传',
                    callback: () => {}
                })
            }

            if (!uploadFlag) {
                window.vueApp.showMsgBox({
                    message: this.$t('minor.approve.uploadFileError'),
                    callback: () => {}
                })
            }
            if (!fileSizeFlag) {
                window.vueApp.showMsgBox({
                    message: this.$t('文件大小不能超过5M'),
                    callback: () => {}
                })
            }
            if (!fileNameLen) {
                window.vueApp.showMsgBox({
                    message: '上传附件名称超长',
                    callback: () => {}
                })
            }

            if (!(uploadFlag && fileSizeFlag && compFileName && fileNameLen)) {
                return false
            }
        },
        handlerUploadSuccess(response, file, fileList) {
            let responseCode = response.code
            if (responseCode === 200) {
                this.uploadFileList.push({
                    number: this.num++,
                    fileId: Object.values(response.data)[0].objectkey,
                    fileName: Object.values(response.data)[0].fileName,
                    fileExt: file.name.substring(file.name.lastIndexOf('.') + 1),
                    fileTime: this.$moment(new Date().getTime()).format('YYYY-MM-DD HH:mm'),
                    fileSize: Math.round((file.raw.size / 1024) * 100) / 100 + ' KB'
                })
                // this.$refs['fileform'].clearValidate(fileds)
            }
        },
        handlerUploadError(response, file, fileList) {
            this.$message({
                message: this.$t('graduateBase.uploadFail'),
                type: 'error'
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.topic-info {
    .topic-title {
        color: #2b3b4e;
        font-size: 18px;
        line-height: 24px;
        font-weight: bold;
    }
    .item {
        margin: 0px;
    }
    .topic-expand {
        color: #3a7fe8;
        font-size: 14px;
        cursor: pointer;
        margin-left: 10px;
    }
    .topic-input-select {
        width: 100%;
    }
    .topic-form-title {
        font-weight: bold;
        text-align: left;
        line-height: 60px;
    }
    .top-title {
        font-weight: bold;
        text-align: left;
        line-height: 30px;
    }
}
</style>
